home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
FROMUTS
/
UNIXLIB37B
/
test
/
c
/
pipetest
< prev
next >
Wrap
Text File
|
1991-09-27
|
663b
|
54 lines
#include <stdio.h>
#include <stdlib.h>
#include "sys/unix.h"
static void copyio(void)
{
char buf[512];
register int n;
while ((n = read(0,buf,512)) > 0) write(1,buf,n);
}
int main()
{
int p[2];
if (pipe(p) < 0) { perror("pipe()"); exit(1); }
switch (vfork())
{
case -1:
perror("vfork()");
exit(1);
break;
case 0:
close(p[0]);
dup2(p[1],1);
close(p[1]);
copyio();
_exit(0);
break;
default:
break;
}
switch (vfork())
{
case -1:
perror("vfork()");
exit(1);
break;
case 0:
close(p[1]);
dup2(p[0],0);
close(p[0]);
copyio();
_exit(0);
break;
default:
break;
}
}